#!/bin/sh
# 参数说明：
# $1 - params path: echo_app_top
# $2 - user cmd: build / clean / ...

print_not_null()
{
    # $1 为空，返回错误
    if [ x"$1" = x"" ]; then
        return 1
    fi

    echo "$1"
}


set -e
cd `dirname $0`

BUILD_PARAM_DIR=$1
BUILD_PARAM_FILE=$BUILD_PARAM_DIR/build_param.config
. $BUILD_PARAM_FILE

EXAMPLE_NAME=$CONFIG_PROJECT_NAME       # the example name selected when ./configure
EXAMPLE_VER=$CONFIG_PROJECT_VERSION     # the version, default is 1.0.0
HEADER_DIR=$OPEN_HEADER_DIR             # the include file directory, default is build/include
LIBS_DIR=$OPEN_LIBS_DIR                 # the libraries file directory, default is build/lib
LIBS=$PLATFORM_NEED_LIBS                # the libraries file, default is libtuyaapp & libtuyaos
OUTPUT_DIR=$BIN_OUTPUT_DIR              # the output file directory, default is build/bin
USER_CMD=$2                             # the user compile command

echo EXAMPLE_NAME=$EXAMPLE_NAME
echo EXAMPLE_VER=$EXAMPLE_VER
echo HEADER_DIR=$HEADER_DIR
echo LIBS_DIR=$LIBS_DIR
echo LIBS=$LIBS
echo OUTPUT_DIR=$OUTPUT_DIR
echo USER_CMD=$USER_CMD

if [ "$USER_CMD" = "build" ]; then
    USER_CMD=all
    mkdir -p $OUTPUT_DIR
    make EXAMPLE_NAME=$EXAMPLE_NAME EXAMPLE_VER=$EXAMPLE_VER LIBS_DIR=$LIBS_DIR LIBS="$LIBS" OUTPUT_DIR=$OUTPUT_DIR HEADER_DIR="$HEADER_DIR" $USER_CMD
    cp -rf $OUTPUT_DIR/${EXAMPLE_NAME}_${EXAMPLE_VER}/${EXAMPLE_NAME}_${EXAMPLE_VER} $(pwd)/kodo-t23-dev/os/rootfs/5.4.0/camera/system/bin
fi

if [ x$USER_CMD = "xclean" ];then
    rm -rf $OUTPUT_DIR
	echo "*************************************************************************"
	echo "************************CLEAN SUCCESS************************************"
	echo "*************************************************************************"
	exit 0
fi

echo add your compile cmds here!
